<template>
<div class="aui-card-list">
 <uni-list-query-card :queryShow="queryShow" @query-click="getDataList()" @click="(e)=>{this.queryShow=e}" @searchReset="searchReset()">
      <el-col :span="6">
        <el-form-item :label="$t('genDataSource.dataSourceName')">
          <el-input v-model="dataForm.dataSourceName" :placeholder="$t('genDataSource.dataSourceName')" clearable></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item :label="$t('genDataSource.dataSourceCode')">
          <el-input v-model="dataForm.dataSourceCode" :placeholder="$t('genDataSource.dataSourceCode')" clearable></el-input>
        </el-form-item>
      </el-col>
 </uni-list-query-card>
  <el-card shadow="never">
    <vxe-toolbar :custom="{immediate:true}">
      <template v-slot:buttons>
        <el-button v-if="$hasPermission('gen:genDataSource:save')" type="primary" @click="addOrUpdateHandle()">
          {{ $t('add') }}</el-button>
        <el-button v-if="$hasPermission('gen:genDataSource:delete')" type="danger" @click="deleteHandle()">
          {{ $t('deleteBatch') }}</el-button>
      </template>
      <template v-slot:tools>
        <el-button icon="el-icon-search" @click="searchShowHandle()" circle></el-button>
        <el-button icon="el-icon-refresh" @click="getDataList()" circle></el-button>
        <!-- <el-button icon="el-icon-download" @click="exportHandle()" circle></el-button> -->
      </template>
    </vxe-toolbar>
    <div class="aui-card-list-body-table">
    <vxe-table ref="xTable" :loading="dataListLoading" class="vxe-table-element" auto-resize :height="this.tableHeight"
      :sort-config="{trigger:'cell'}" @sort-change="sortChange" @select-change="dataListSelectionChangeHandleVex"
      @select-all="dataListSelectionAllChangeHandleVex" :data="dataList" max-height="auto">
      <vxe-table-column type="checkbox" align="center" width="60"></vxe-table-column>
      <!--数据源名称  -->
      <vxe-table-column field="dataSourceName" title="genDataSource.dataSourceName">
      </vxe-table-column>
      <!--数据源代码  -->
      <vxe-table-column field="dataSourceCode" title="genDataSource.dataSourceCode">
      </vxe-table-column>
      <!--驱动名称  -->
      <vxe-table-column field="driverClassName" title="genDataSource.driverClassName">
      </vxe-table-column>
      <!--用户名  -->
      <vxe-table-column field="userName" title="genDataSource.userName">
      </vxe-table-column>
      <!--更新时间(YYYY-MM-DD HH:MM:SS)  -->
      <vxe-table-column field="updateDate" title="common.updateDate">
      </vxe-table-column>
      <!--更新人  -->
      <vxe-table-column field="updater" title="common.updater">
      </vxe-table-column>
      <vxe-table-column title="handle" align="center" show-overflow="false" width="120" fixed="right">
        <template slot-scope="scope">
          <el-button v-if="$hasPermission('gen:genDataSource:update')" type="text" size="small" icon="el-icon-edit"
            @click="addOrUpdateHandle(scope.row)">{{ $t('update') }}</el-button>
          <el-button v-if="$hasPermission('gen:genDataSource:delete')" type="text" size="small" icon="el-icon-delete"
            @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
        </template>
      </vxe-table-column>
    </vxe-table>
    <el-pagination :current-page="page" :page-sizes="pageSizes" :page-size="limit" :total="total"
      layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
      @current-change="pageCurrentChangeHandle">
    </el-pagination>
    </div>
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </el-card>
</div>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './genDataSource-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      searchShow: true,
      mixinViewModuleOptions: {
        getDataListURL: '/gen/genDataSource/page',
        getDataListIsPage: true,
        deleteURL: '/gen/genDataSource',
        deleteIsBatch: true,
        exportURL: '/gen/genDataSource/export'
      },
      headLock: true,
      dataForm: {
        dataSourceName: '',
        dataSourceCode: '',
        driverClassName: '',
        userName: '',
        status: ''
      }
    }
  },
  components: {
    AddOrUpdate
  },
  methods: {
    // 新增 / 修改
    addOrUpdateHandle (row) {
      let id
      if (row) {
        id = row.id
      }
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.dataForm.id = id
        this.$refs.addOrUpdate.init()
      })
    }
  }
}
</script>
